package com.aigc.sclassroom.controller;

import com.aigc.sclassroom.pojo.ChatMessage;
import com.aigc.sclassroom.service.ChatMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/chatmessage")
public class ChatHistoryController {

    @Autowired
    private ChatMessageService chatMessageService;

    @GetMapping("/chathistory")
    public List<ChatMessage> getChatHistory(@RequestParam String sender, @RequestParam String receiver) {
        if ("group".equals(receiver)) {
            return chatMessageService.getGroupChatHistory(sender, receiver);
        } else {
            return chatMessageService.getChatHistory(sender, receiver);
        }
    }



}